//
//  HRMainTabBarController.m
//  网易彩票
//
//  Created by rui on 6/29/15.
//  Copyright © 2015 loverforevercyr. All rights reserved.
//

#import "HRMainTabBarController.h"
#import "HRMainNavigationController.h"

#import "HRTabBar.h"
#import "HRTabBarItem.h"

#import "HRHomeNavigationController.h"
#import "HRHomeViewController.h"


@interface HRMainTabBarController () <HRTabBarDelegate>

@property(nonatomic, weak) HRTabBar         *myTabBar;

@end

@implementation HRMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 添加所有的子控件
    [self setUpChildControllers];
    
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
    
    
    // 设置底部的UITabar
    [self setUpTabBar];
    self.myTabBar.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 添加所有的子控件
- (void)setUpChildControllers {
    // 1.设置“主页”的控制器
    HRHomeViewController *homeVC = [[HRHomeViewController alloc] init];
//    hallTVC.view.backgroundColor = randomColor;
    HRMainNavigationController *homeNC = [[HRMainNavigationController alloc] initWithRootViewController:homeVC];
    [self addChildViewController:homeNC];
//
//    // 2.设置“竞技场大厅”的控制器
//    HRArenaController *arenaVC = [[HRArenaController alloc] init];
////    arenaVC.view.backgroundColor = randomColor;
//    HRArenaNavigationController *arenaNC = [[HRArenaNavigationController alloc] initWithRootViewController:arenaVC];
//    [self addChildViewController:arenaNC];
//    
//    // 3.设置“发现”的控制器
//    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Discovery" bundle:nil];
//    HRDiscoveryTableViewController *discoveryTVC = [storyboard instantiateInitialViewController];
////    discoveryTVC.view.backgroundColor = randomColor;
//    HRMainNavigationController *discoveryNC = [[HRMainNavigationController alloc] initWithRootViewController:discoveryTVC];
//    [self addChildViewController:discoveryNC];
//    
//    // 4.设置“开奖信息”控制器
//    HRHistoryTableViewController *historyTVC = [[HRHistoryTableViewController alloc] init];
////    historyTVC.view.backgroundColor = randomColor;
//    HRMainNavigationController *historyNC = [[HRMainNavigationController alloc] initWithRootViewController:historyTVC];
//    [self addChildViewController:historyNC];
//    
//    // 5.设置“我的彩票”控制器
//    HRMyLotteryController *myLotteryVC = [[HRMyLotteryController alloc] init];
////    myLotteryVC.view.backgroundColor = randomColor;
//    HRMainNavigationController *myLotteryNC = [[HRMainNavigationController alloc] initWithRootViewController:myLotteryVC];
//    [self addChildViewController:myLotteryNC];
    
}

#pragma mark - 自定义底部的UITabBar
- (void)setUpTabBar {
    // 初始化每个自控制器对应的HRTabBarItem的模型tabBarItemClick
    // 1.首页
    HRTabBarItem *hallTabBarItem = [[HRTabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"icon_home"] selectedImage:[UIImage imageNamed:@"icon_home_selected"]];
    
    // 2.发现
    HRTabBarItem *arenaTabBarItem = [[HRTabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"icon_discovery"] selectedImage:[UIImage imageNamed:@"icon_discovery_selected"]];
    
    // 3.社区
    HRTabBarItem *discoveryTabBarItem = [[HRTabBarItem alloc] initWithTitle:@"社区" image:[UIImage imageNamed:@"icon_zone"] selectedImage:[UIImage imageNamed:@"icon_zone_selected"]];
    
    // 4.账号
    HRTabBarItem *historyTabBarItem = [[HRTabBarItem alloc] initWithTitle:@"账号" image:[UIImage imageNamed:@"icon_me"] selectedImage:[UIImage imageNamed:@"icon_me_selected"]];
    
    // 5.设置
    HRTabBarItem *myLotteryTabBarItem = [[HRTabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"icon_setting"] selectedImage:[UIImage imageNamed:@"icon_setting_selected"]];
    
    // 创建一个HRTabBar控件，并将它添加到底部栏上，覆盖原来的UITabBar控件
    HRTabBar *tabBar = [[HRTabBar alloc] initWithFrame:self.tabBar.bounds];
    [self.tabBar addSubview:tabBar];
    self.myTabBar = tabBar;
    self.myTabBar.items = @[hallTabBarItem, arenaTabBarItem, discoveryTabBarItem, historyTabBarItem, myLotteryTabBarItem];
    self.myTabBar.backgroundColor = [UIColor colorWithRed:12 / 255.0 green:12 / 255.0 blue:12 / 255.0 alpha:0.7];
}

#pragma mark - HRTabBarDelegate 
- (void)tabBar:(HRTabBar *)tabBar didSelectedAtIndex:(NSUInteger)index {
    self.selectedIndex = index;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
